<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                template="./../template/AdminTemplate.xhtml">

    <ui:define name="contentInsert">

        <h2>Stakeholder Management System</h2>
        
        <h3>Delete Stakeholder</h3>
        <h:form id="deleteForm" prependId="true">
            <p:panel id="panel" >
                <p:ajaxStatus style="width:16px;height:16px;">
                    <f:facet name="start">
                        <h:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" />
                    </f:facet>
                    <f:facet name="complete">
                        <h:outputText value="" />
                    </f:facet>
                </p:ajaxStatus>
                <p:messages />  
            </p:panel>

            <p:dataTable value="#{stakeholderAccountsManagerBean.getAllStakeholders()}" var="o" paginator="true" rows="15"
                         >


                <p:column headerText="Stakeholder Name" filterBy="#{o.name}" filterMatchMode="contains">
                            #{o.name}
                </p:column>

                <p:column headerText="Category" filterBy="#{o.category.description}" filterMatchMode="contains">
                            #{o.category.description}
                </p:column>

                <p:column headerText="Phone No.">
                            #{o.phoneNo}
                </p:column>


                <p:column headerText="Loyalty points">
                            #{o.loyaltyPoints}
                </p:column>


                <p:column headerText="Tier" filterBy="#{o.getStakeholderTier().getName()}" filterMatchMode="contains" >
                            #{o.getStakeholderTier().getName()}
                </p:column>  



                <p:column>
                    <p:commandButton  value="Delete" 
                                      onclick="if (!confirm('Are you sure you want to delete #{o.name}?')) return false"
                                      action="#{stakeholderAccountsManagerBean.deleteStakeholder(o)}"
                                      >
                    </p:commandButton>
                </p:column>
                
            </p:dataTable>



            <p:confirmDialog id="confirmation" message="Are you sure you want to delete #{stakeholderAccountsManagerBean.selectedStakeholder.name}?"
                             header="Delete process"
                             widgetVar="confirmation"
                             >  

                <p:commandButton value="Yes" oncomplete="confirmation.hide()"  
                                 action="#{stakeholderAccountsManagerBean.deleteStakeholder}" ajax ="false">
                </p:commandButton>
                <p:commandButton value="No" onclick="confirmation.hide()" />   
            </p:confirmDialog>


        
        

        <br/>
        <br/>       

         </h:form>
         <br/><br/>
        <h3>Add New Stakeholder</h3>
        <h:form>
            <p:panel id="panel" >
                <p:ajaxStatus style="width:16px;height:16px;">
                    <f:facet name="start">
                        <h:graphicImage value="http://www.primefaces.org:8080/showcase/design/ajaxloading.gif" />
                    </f:facet>
                    <f:facet name="complete">
                        <h:outputText value="" />
                    </f:facet>
                </p:ajaxStatus>
                <p:messages />
                <h:panelGrid columns="3">
                    <h:outputLabel for="stakeholderName" value="Stakeholder name:"/>
                    <p:inputText required="true" requiredMessage="Stakeholder name is requied!"
                                 id="stakeholderName" value="#{stakeholderAccountsManagerBean.stakeholderName}"/>
                    <p:message for="stakeholderName"/>
                    
                    <h:outputLabel value="Stakeholder Category: "/>
                    <h:selectOneMenu value="#{stakeholderAccountsManagerBean.categoryDescription}">
                        <f:selectItems value="#{categoryManagerBean.getAllCategories()}" var="c" itemLabel="#{c.description}" itemValue="#{c.description}" />
                    </h:selectOneMenu>
                    <div></div> <!--dummy div to fill the panel grid(must have 3 rows) -->
                    
                    
                    

                    <h:outputLabel for="loyaltyPoints" value="Initial loyalty points: "/>
                    <p:inputText required="true" requiredMessage="initial loyalty points required"
                                 id="loyaltyPoints" value="#{stakeholderAccountsManagerBean.loyaltyPoints}"/>
                    <p:message for="loyaltyPoints"/>

                    
                    <h:outputLabel for="address" value="Address: "/>
                    <p:inputText required="true" requiredMessage="Address required!" id="address"
                                 value="#{stakeholderAccountsManagerBean.address}">
                    </p:inputText>
                    <p:message for="address"/>
                    
                    
                    <h:outputLabel for="phoneNo" value="Phone Number "/>
                    <p:inputText required="true" requiredMessage="Phone Number required!" id="phoneNo"
                                 value="#{stakeholderAccountsManagerBean.phoneNo}">
                    </p:inputText>
                    <p:message for="phoneNo"/>

                    
                    <h:outputLabel for="postalCode" value="Postal Code"/>
                    <p:inputText required="true" requiredMessage="Postal Code required!" id="postalCode"
                                 value="#{stakeholderAccountsManagerBean.postalCode}">
                    </p:inputText>
                    <p:message for="postalCode"/>
                    

                    <h:outputLabel value="Stakeholder's Membership Tier: "/>
                    <h:selectOneMenu value="#{stakeholderAccountsManagerBean.stakeholderTier}">
                        <f:selectItems value="#{tierManagerBean.allTiers}" var="c" itemLabel="#{c.name}" itemValue="#{c.name}" />
                    </h:selectOneMenu>
                    
                    
                    
                </h:panelGrid>
                <br/>

                <br/>
                <p:commandButton id="submitNewStakeholder" value="Create Account" onclick="if (!confirm('Are you sure you want to create new stakeholder?')) return false"
                                 action="#{stakeholderAccountsManagerBean.createStakeholder(event)}"
                                 ajax="false"
                                 />
                </p:panel>
        </h:form>
            

    </ui:define>
</ui:composition>
